package edu.ccit.shudong.service.impl;

import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import edu.ccit.shudong.entity.Comment;
import edu.ccit.shudong.entity.Post;
import edu.ccit.shudong.mapper.CommentMapper;
import edu.ccit.shudong.service.ICommentService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import edu.ccit.shudong.service.IPostService;
import edu.ccit.shudong.service.IUserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;
import java.util.function.Function;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author Suting Luo
 * @since 2024-06-14
 */
@Service
public class CommentServiceImpl extends ServiceImpl<CommentMapper,Comment> implements ICommentService {
    @Autowired
    private CommentMapper commentMapper;

    @Autowired
    private IPostService postService;

    @Autowired
    private IUserService userService;

    @Value("${bed.url.prefix}")
    private String bedUrlPrefix;


    @Override
    public List<Comment> findListByUserId(long userId) {
        return Collections.emptyList();
    }

    @Override
    public List<Comment> findByUserId(long userId) {
        return Collections.emptyList();
    }

    @Override
    public List<Comment> findListByPostId(long postId) {
        return Collections.emptyList();
    }

    @Override
    public Comment addOne(long userId, long postId, String content) {

        if (!postService.exists(new QueryWrapper<Post>().eq("id", postId))) return null;

        Comment comment = new Comment();
        comment.setUserId(userId);
        comment.setPostId(postId);
        comment.setContent(content);
        if (this.save(comment)) {
            comment = commentMapper.findById(comment.getId());
            comment.setAvatar(bedUrlPrefix + comment.getAvatar());
            return comment;
        }
        return null;
    }

    @Override
    public Comment findById(long id) {
        return null;
    }

    @Override
    public boolean saveOrUpdate(Comment entity) {
        return false;
    }

}
